<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'interfaces/i_db_storable.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/tcms_registry_keys.class.php');
require_once($WSC->get_site_inc_dir().'modules/registry_db/registry_key_db.class.php');


class TCMS_Settings_Attachments_DBC extends Tangra_Class implements I_DB_Storable {
	private $id;
	private $max_size;
	private $max_total_size;
	private $forbidden_extensions;
	private $upload_path;


	//fake
	public function set_id($id) {
	}


	//fake
	public function get_id() {
		return 1;
	}


	public function save(DB_Connection $dbc) {
		$this->max_size->save($dbc);
		$this->max_total_size->save($dbc);
		$this->forbidden_extensions->save($dbc);
		$this->upload_path->save($dbc);

		return 1;
	}


	public function load_by_id(DB_Connection $dbc, $id) {
		tangra_if_not_int_throw_e($id);


		$max_size_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_MAX_SIZE);
		if ($max_size_id) {
			$max_size = new Registry_Key_DB();
			$max_size->load_by_id($dbc, $max_size_id);
			$this->max_size = $max_size;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_MAX_SIZE);
		}


		$max_total_size_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_MAX_TOTAL_SIZE);
		if ($max_total_size_id) {
			$max_total_size = new Registry_Key_DB();
			$max_total_size->load_by_id($dbc, $max_total_size_id);
			$this->max_total_size = $max_total_size;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_MAX_TOTAL_SIZE);
		}


		$forbidden_extensions_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_FORBIDDEN_EXTENSIONS);
		if ($forbidden_extensions_id) {
			$forbidden_extensions = new Registry_Key_DB();
			$forbidden_extensions->load_by_id($dbc, $forbidden_extensions_id);
			$this->forbidden_extensions = $forbidden_extensions;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_FORBIDDEN_EXTENSIONS);
		}

		$upload_path_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_UPLOAD_PATH);
		if ($upload_path_id) {
			$upload_path = new Registry_Key_DB();
			$upload_path->load_by_id($dbc, $upload_path_id);
			$this->upload_path = $upload_path;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_ATTACHMENTS_UPLOAD_PATH);
		}

		return 1;
	}


	public function set_max_size($value) {
		$this->max_size->set_value($value);
	}


	public function get_max_size() {
		return $this->max_size->get_value();
	}


	public function set_max_total_size($value) {
		$this->max_total_size->set_value($value);
	}


	public function get_max_total_size() {
		return $this->max_total_size->get_value();
	}


	public function set_forbidden_extensions($value) {
		$this->forbidden_extensions->set_value($value);
	}


	public function get_forbidden_extensions() {
		return $this->forbidden_extensions->get_value();
	}

	public function set_upload_path($value) {
		$this->upload_path->set_value($value);
	}


	public function get_upload_path() {
		return $this->upload_path->get_value();
	}
}